package com.byxy.ssm.demo.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.byxy.ssm.demo.VO.TipVO;
import com.byxy.ssm.demo.dao.ForumDao;
import com.byxy.ssm.demo.dao.TabDao;
import com.byxy.ssm.demo.dao.TipDao;
import com.byxy.ssm.demo.dao.UserDao;
import com.byxy.ssm.demo.entity.Forum;
import com.byxy.ssm.demo.entity.Tab;
import com.byxy.ssm.demo.entity.Tip;
import com.byxy.ssm.demo.entity.User;
import com.byxy.ssm.demo.service.TipService;

@Service
@Transactional
public class TipServerImpl implements TipService {
	
	@Autowired
	private TipDao tipDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private TabDao tabDao;
	@Autowired
	private ForumDao forumDao;

	public List<TipVO> tips() {
		List<TipVO> tipVOs = new ArrayList<TipVO>();
		for(Tip tip:tipDao.tips()) {
			User user = userDao.getById(tip.getUserId());
			user.setUserPassword(null);
			Tab tab = tabDao.getById(tip.getTabId());
			Forum forum = forumDao.getById(tab.getForumId());
			tipVOs.add(new TipVO(tip.getTipId(), user, tab,forum, tip.getTipTitle(), tip.getTipContent(), tip.getTipPublishTime(), tip.getTipModifyTime(), tip.getTipClick(), tip.getTipIsDeleted(), tip.getTipIsKnot(), tip.getTipReplies()));
		}
		return tipVOs;
	}

}
